export default {
  total: (list) => {
    let count = 0

    list = list.filter(x => x.selected === '1' || x.selected === true)
    list.forEach(x => {
      count += +x.quantity
    })
    // console.log(count)
    if (count > 0) {
      if (count > 99) {
        count = '99+'
      }
      wx.setTabBarBadge({
        index: 2,
        text: count.toString()
      })
    } else {
      wx.hideTabBarRedDot({
        index: 2,
      })
    }
  },

  getTotal(list) {
    let count = 0

    list = list.filter(x => x.selected === '1' || x.selected === true)
    list.forEach(x => {
      count += +x.quantity
    })

    if (count > 99) {
      count = '99+'
    }

    if (count <= 0) {
      count = ''
    }

    return count.toString()
  }
}
